<template>
	<view>
		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #e64340;">&#xe8ce;</text>论文数</view>
			<view class="input-content">
				<input class="text-input" type="number" placeholder="请输入论文数" v-model="paperNumber" />
			</view>
		</view>
		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #c60ce6;">&#xe62e;</text>专著数</view>
			<view class="input-content">
				<input class="text-input" type="number" placeholder="请输入专著数" v-model="treatiseNumber" />
			</view>
		</view>
		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #14e6a0;">&#xe6eb;</text>项目数</view>
			<view class="input-content">
				<input class="text-input" type="number" placeholder="请输入项目数" v-model="projectNumber" />
			</view>
		</view>
		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #f8ea24;">&#xe7fc;</text>获奖数</view>
			<view class="input-content">
				<input class="text-input" type="number" placeholder="请输入获奖数" v-model="awardNumber" />
			</view>
		</view>
		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #47e6c7;">&#xe660;</text>专利数</view>
			<view class="input-content">
				<input class="text-input" type="number" placeholder="请输入专利数" v-model="patentNumber" />
			</view>
		</view>
		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #de9ae6;">&#xe604;</text>国家项目数</view>
			<view class="input-content">
				<input class="text-input" type="number" placeholder="请输入国家项目数" v-model="countryProjectNumber" />
			</view>
		</view>
		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #4ce6a1;">&#xe604;</text>国家立项数</view>
			<view class="input-content">
				<input class="text-input" type="number" placeholder="请输入国家立项数" v-model="countryProjectLeaderNumber" />
			</view>
		</view>
		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #80e63c;">&#xe604;</text>省级项目数</view>
			<view class="input-content">
				<input class="text-input" type="number" placeholder="请输入省级项目数" v-model="provienceProjectNumber" />
			</view>
		</view>
		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #1b25e6;">&#xe604;</text>省级立项数</view>
			<view class="input-content">
				<input class="text-input" type="number" placeholder="请输入省级立项数" v-model="provienceProjectLeaderNumber" />
			</view>
		</view>
		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #5c71e6;">&#xe62f;</text>招生专业</view>
			<view class="input-content">
				<picker @change="majorIndex=$event.detail.value" :value="majorIndex" :range="major">
					<text>{{major[majorIndex]}}</text>
				</picker>
			</view>
		</view>
		<view class="bottom">
			<button type="primary" @click="submit"><text class="iconfont" style="color: #FFFFFF;">&#xe64a;</text>保存信息</button>
		</view>
	</view>
</template>
<script>
	import {
		init,
		recruitInsert,
		recruitUpdate,
		delRecruitApply
	} from '@/api/tRecruit.js'

	function timeFormat() {
		const date = new Date()
		let year = date.getFullYear()
		let month = date.getMonth() + 1
		let day = date.getDate()
		let hour = date.getHours()
		let min = date.getMinutes()
		let second = date.getSeconds()
		month = month > 9 ? month : '0' + month
		day = day > 9 ? day : '0' + day;
		hour = hour > 9 ? hour : '0' + hour;
		min = min > 9 ? min : '0' + min;
		second = second > 9 ? second : '0' + second;
		return `${year}-${month}-${day} ${hour}:${min}:${second}`
	}
	export default {
		data() {
			return {
				teaRecruitId: '',//0表示新增
				tid: '',
				paperNumber: 0,
				treatiseNumber: 0,
				projectNumber: 0,
				awardNumber: 0,
				patentNumber: 0,
				countryProjectNumber: 0,
				countryProjectLeaderNumber: 0,
				provienceProjectNumber: 0,
				provienceProjectLeaderNumber: 0,
				major: ['请选择招生专业', '软件工程', '计算机科学与技术', '数学', '统计学'],
				majorIndex: 0,
				teaRecruitApplyId:''
			}
		},
		methods: {
			getData() {
				uni.showLoading()
				init({
					tid: this.tid
				}).then(res => {
					// console.log(res)
					this.paperNumber = res.data.data.paperNumber,
						this.treatiseNumber = res.data.data.treatiseNumber,
						this.projectNumber = res.data.data.projectNumber,
						this.awardNumber = res.data.data.awardNumber,
						this.patentNumber = res.data.data.patentNumber,
						this.countryProjectNumber = res.data.data.countryProjectNumber,
						this.countryProjectLeaderNumber = res.data.data.countryProjectLeaderNumber,
						this.provienceProjectNumber = res.data.data.provinceProjectNumber,
						this.provienceProjectLeaderNumber = res.data.data.provinceProjectLeaderNumber
					uni.hideLoading()
				}).catch(err => {
					uni.hideLoading()
					uni.showModal({
						content: '请求失败',
						showCancel: false
					})
				})
			},
			submit() {
				if (this.majorIndex === 0) {
					uni.showModal({
						content: '请选择招生专业',
						showCancel: false
					})
					return
				}
				let data = {
					tid: this.tid,
					paperNumber: this.paperNumber,
					treatiseNumber: this.treatiseNumber,
					projectNumber: this.projectNumber,
					awardNumber: this.awardNumber,
					patentNumber: this.patentNumber,
					countryProjectNumber: this.countryProjectNumber,
					countryProjectLeaderNumber: this.countryProjectLeaderNumber,
					provinceProjectNumber: this.provienceProjectNumber,
					provinceProjectLeaderNumber: this.provienceProjectLeaderNumber,
					major: this.major[this.majorIndex],
					time: timeFormat()
				}
				if(this.teaRecruitId=='0'){ //新增
					recruitInsert(data).then(res => {
						// console.log(res)
						if (res.data.code == 0) {
							uni.showModal({
								content: '提交成功',
								showCancel: false,
								success:()=> {
									// delRecruitApply({
									// 	teaRecruitApplyId:this.teaRecruitApplyId
									// })
									uni.navigateBack()
								}
							})
						} else {
							uni.showModal({
								content: '提交失败',
								showCancel: false
							})
						}
					})
				}else { //修改
					data.teaRecruitId = this.teaRecruitId
					recruitUpdate(data).then(res => {
						if (res.data.code == 0) {
							uni.showModal({
								content: '提交成功',
								showCancel: false,
								success:()=> {
									// delRecruitApply({
										// teaRecruitApplyId:this.teaRecruitApplyId
									// })
									uni.navigateBack()
								}
							})
						} else {
							uni.showModal({
								content: '提交失败',
								showCancel: false
							})
						}
					})
				}
			}
		},
		onLoad(option) {
			// console.log(option)
			this.teaRecruitId = option.teaRecruitId
			this.teaRecruitApplyId = option.teaRecruitApplyId
			this.tid = getApp().globalData.tid
			this.getData()
		}
	}
</script>

<style>
	page{
		font-family: 'Courier New', Courier, monospace;
	}
	.iconfont {
		font-family: "iconfont" !important;
		font-size: 16px;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
		margin-right: 5px;
	}
	.input-item {
		height: auto;
		position: relative;
		height: 40px;
		margin: 0 5px;
		border-bottom: 1px dotted #C0C0C0;
		margin: 5px 8px;
		box-shadow: 2px 2px 1px #cedce2;
	}

	.input-item .title {
		position: absolute;
		top: 0;
		left: 0;
		width: 50%;
		height: 100%;
		/* text-align: center; */
		line-height: 40px;
		padding-left: 10px;
	}

	.input-item .input-content {
		position: absolute;
		top: 0;
		right: 0;
		width: 50%;
		height: 100%;
	}

	.input-item .input-content .text-input {
		position: absolute;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 100%;
	}

	.bottom {
		margin-top: 30px;
		padding: 0 10px;
	}

	.input-item .input-content picker {
		margin-top: 8px;
		font-size: 18px;
	}
</style>
